package com.zxjbyte.yiyi.extension.job.core.trigger;

import cn.hutool.core.util.StrUtil;
import com.zxjbyte.yiyi.framework.common.util.ValidationUtil;
import org.quartz.TriggerKey;

/**
 * 构建触发器键
 *
 * @Author zhangxingjia
 * @Date 2023/9/12 15:08
 * @Version: 1.0
 */
public class TriggerKeyBuilder {

    public static final String TRIGGER_KEY_DEFAULT_GROUP = "MY_TRIGGER_GROUP";


    /**
     * 创建触发器键
     * @param name 名称
     * @param group 分组
     * @return
     */
    public static TriggerKey newTriggerKey(String name, String group){
        ValidationUtil.assertNotBlank(name, "TriggerKey name");
        group = StrUtil.isBlank(group) ? TRIGGER_KEY_DEFAULT_GROUP : group;
        return TriggerKey.triggerKey(name, group);
    }

    /**
     * 创建触发器键
     * @param name 名称
     * @param group 分组
     * @return
     */
    public static TriggerKey newTriggerKey(String name, String... group){
        if(group != null && group.length >= 1){
            return newTriggerKey(name, group[0]);
        } else {
            return newTriggerKey(name);
        }
    }

    /**
     * 创建触发器键
     * @param name 名称
     * @return
     */
    public static TriggerKey newTriggerKey(String name){
        return newTriggerKey(name, TRIGGER_KEY_DEFAULT_GROUP);
    }
}
